package visualizeData;
import java.awt.BorderLayout;
import java.awt.Rectangle;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;

public class VisualizeData extends JPanel {
	
	public VisualizeData(String chartName,String xLabel,String yLabel) {
		super();

		// create a dataset...
		XYSeries series = new XYSeries("Increase");
		XYSeries series1 = new XYSeries("Decrease");

		XYSeries series2 = new XYSeries("Increase1");
		XYSeries series3 = new XYSeries("Decrease2");
		
		
//		[[0.4,-0.31712050213544574][0.8,-0.2206075122482234][1.2000000000000002,-0.22048627435378954][1.3333333333333335,-0.16621080249819542][1.4666666666666668,-0.04380803261927113][1.6,0.0]]
//		[[0.4,-0.31712050213544574][0.8,-0.2206075122482234][1.2000000000000002,-0.22072879793035716][1.3333333333333335,-0.16623950573458757][1.4666666666666668,-0.04357829187203066][1.6,0.0]]

				
//		series.add(0.4,-0.31712050213544574)				;
//		series.add(0.8,-0.2206075122482234);
//		series.add(1.2000000000000002,-0.22048627435378954);
//		series.add(1.3333333333333335,-0.16621080249819542);
//		series.add(1.4666666666666668,-0.04380803261927113);
//		series.add(1.6,0.0);
//
//		series1.add(0.4,-0.31712050213544574);
//		series1.add(0.8,-0.2206075122482234);
//		series1.add(1.2000000000000002,-0.22072879793035716);
//		series1.add(1.3333333333333335,-0.16623950573458757);
//		series1.add(1.4666666666666668,-0.04357829187203066);
//		series1.add(1.6,0.0);
		
		series.add(0.4,0.9383068269626386);
		series.add(0.8,0.9411250958794392);
		series.add(1.2000000000000002,0.9411804800932426);
		series.add(1.6,0.0);
		
		series1.add(0.4,0.9383068269626386);
		series1.add(0.8,0.9411250958794392);
		series1.add(1.2000000000000002,0.9410696627813425);
		series1.add(1.6,0.0);
		
		series2.add(0.4,0.9389325188438505);
		series2.add(0.8,0.9411250958794392);
		series2.add(1.2000000000000002,0.9411804800932426);
		series2.add(1.6,0.0);


		series3.add(0.4,0.9389325188438505);
		series3.add(0.8,0.9411250958794392);
		series3.add(1.2000000000000002,0.9410696627813425);
		series3.add(1.6,0.0);
		
		
		XYSeriesCollection dataset = new XYSeriesCollection();
//		XYSeriesCollection dataset13 = new XYSeriesCollection();
//		XYSeriesCollection dataset10 = new XYSeriesCollection();
//		XYSeriesCollection dataset11 = new XYSeriesCollection();
//		XYSeriesCollection dataset12 = new XYSeriesCollection();
		
		dataset.addSeries(series);
		dataset.addSeries(series1);
		dataset.addSeries(series2);
		dataset.addSeries(series3);
//		dataset12.addSeries(series4);
//		dataset13.addSeries(series5);

		JFreeChart chart = ChartFactory.createXYLineChart(chartName,
				xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true, true);

//		JFreeChart chart13 = ChartFactory.createXYLineChart(chartName,
//				xLabel, yLabel, dataset13, PlotOrientation.VERTICAL, true, true, true);
//
//		JFreeChart chart10 = ChartFactory.createXYLineChart(chartName,
//				xLabel, yLabel, dataset10, PlotOrientation.VERTICAL, true, true, true);
//
//		JFreeChart chart11 = ChartFactory.createXYLineChart(chartName,
//				xLabel, yLabel, dataset11, PlotOrientation.VERTICAL, true, true, true);
//
//		JFreeChart chart12 = ChartFactory.createXYLineChart(chartName,
//				xLabel, yLabel, dataset12, PlotOrientation.VERTICAL, true, true, true);

//		org.jfree.chart.plot.XYPlot plot = (XYPlot) chart.getPlot();
		
		int xm = 750;
		ChartPanel chartPanel = new ChartPanel(chart, xm, xm, xm, xm, xm, xm, true, true, true, true, true, true, true);

//		ChartPanel chartPanel13 = new ChartPanel(chart13, 350, 350, 350, 350, 350, 350, true, true, true, true, true, true, true);
//		ChartPanel chartPanel10 = new ChartPanel(chart10, 350, 350, 350, 350, 350, 350, true, true, true, true, true, true, true);
//		ChartPanel chartPanel11 = new ChartPanel(chart11, 350, 350, 350, 350, 350, 350, true, true, true, true, true, true, true);
//		ChartPanel chartPanel = new ChartPanel(chart, 350, 350, 350, 350, 350, 350, true, true, true, true, true, true, true);
//		ChartPanel chartPanel12 = new ChartPanel(chart12, 350, 350, 350, 350, 350, 350, true, true, true, true, true, true, true);

		
		
		add(chartPanel);
//		add(chartPanel13);
//		add(chartPanel10);
//		add(chartPanel11);
//		add(chartPanel12);
	}

	private XYSeries createSeries(int n1,int n2,String seriesName){
		
		
		String fFileName = "Log/weightstates.txt";
		XYSeries series2 = new XYSeries(seriesName);

		try {
			Scanner scanner = new Scanner(new FileInputStream(fFileName));
//			String NL = System.getProperty("line.separator");


			while (scanner.hasNextLine()){
//				 System.out.print("Number"+scanner.nextDouble());
			     String m1 = scanner.nextLine();   
//				 System.out.println(scanner.nextLine());
			     
			     String[] m2= m1.split(",");
			     
//			     System.out.println(m1);
			     
			     if (Integer.valueOf(m2[1]) == n1 && Integer.valueOf(m2[2]) == n2 ){
			    	 System.out.println(Integer.valueOf(m2[0])+","+Double.valueOf(m2[3]));
			    	 series2.add(Integer.valueOf(m2[0]), Double.valueOf(m2[3]));
			     }
			     
			 }
			
			scanner.close();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		


		return series2;
		
	}
	
	
	
	
	public static void main(String[] args) {
		
		JPanel panel=new JPanel();
//		panel.setBounds(new Rectangle(1000,1024));
		JFrame frame = new JFrame("Algorithm Performance Stats");
		
//		JScrollPane scrollBar=new JScrollPane(panel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); 
		

		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.add(panel);
//		
//		frame.add(scrollBar);  

//		p.setVisible(true);
		frame.getContentPane().add(new VisualizeData("Weigth Error Data", "xLabel","yLabel"), BorderLayout.CENTER);

		frame.pack();
		frame.setVisible(true);
	}
}